#include <func.h>

int print_dir(char *path,int width)
{
    DIR* dir;
    dir=opendir(path);
    ERROR_CHECK(dir,NULL,"opendir");
    struct dirent *p;
    while(p=readdir(dir))
    {
        if(strcmp(p->d_name,".")==0||strcmp(p->d_name,"..")==0)
        {
            continue;
        }

        //目录则递归。文件名则输出
        printf("%*s%s\n",width," ",p->d_name);        
        if(p->d_type==4)
        {
            //要进行路径拼接
            char path_buf[1024];
            sprintf(path_buf,"%s/%s",path,p->d_name);
            print_dir(path_buf,width+4);
        }
    }
    closedir(dir);
    return 0;
}

int main(int argc,char* argv[])
{
    ARGS_CHECK(argc,2);
    print_dir(argv[1],0);
    return 0;
}